# 假设文件名为hex_file.txt
file_name = r'../file/hexdemo.txt'

# 读取文件内容
with open(file_name, 'r') as file:
    hex_string = file.read()

# 将16进制字符串每两个字符分割，并用空格连接
formatted_hex_string = ' '.join([hex_string[i:i+2] for i in range(0, len(hex_string), 2)])

# 打印结果
# print(formatted_hex_string)

# 假设输出文件名为formatted_hex_file.txt
output_file_name = '../file/hexdemo_2.txt'

# 将格式化后的字符串写入新文件
with open(output_file_name, 'w') as file:
    file.write(formatted_hex_string)